/**
 * Copyright (c) 2018-present, Chen Guodong
 * All rights reserved.
 *
 * @flow
 */


<template>
  <section class="content">
    <Header title="项目选择"></Header>
    <div class="main">
      <div
        class="item"
        v-for="(item,index) in  data"
        :key="index"
        @click="handlerItem(item)"
      >{{item.name}}</div>
    </div>
  </section>
</template>

<script>
import Header from "../../components/Header/Header";
import { getAllProject } from "../../api/index.js";
export default {
  data() {
    return {
      data: []
    };
  },
  mounted() {
    let l = JSON.parse(localStorage.getItem("projectInfo"));
    if (l) {
      this.data = l;
    } else {
      console.log("没有项目信息");
      this.getData();
    }
  },
  methods: {
    handlerItem(data) {
      localStorage.setItem("selectedProject", JSON.stringify(data));
      this.$router.push({ path: "/home" });
    },
    async getData(){
      let result = await getAllProject();
    if (result.code === 1) {
      this.data = result.data;
    } else {
      this.$vux.toast.show(`获取专业科目信息列表失败:${result.msg}`);
    }
    }
  },
  components: {
    Header
  }
};
</script>

<style lang='less' scoped>
@import "../../util/theme.less";

.content {
  .be-full();
  .main {
    width: 100%;
    height: calc(~"100% - 46px");
    padding: 15px;
    box-sizing: border-box;
    .item {
      display: inline-block;
      width: calc(~"50% - 5px");
      height: 60px;
      box-sizing: border-box;
      background: #fff;
      margin-bottom: 10px;
      border-radius: 5px;
      font-size: 12px;
      padding: 8px;
      box-shadow: 3px 5px 2px 0px rgba(0, 0, 0, 0.1);
      &:nth-child(2n-1) {
        margin-right: 10px;
      }
    }
  }
}
</style>
